<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title> - polygon.coffee</title>

  <link rel="stylesheet" href="../../../assets/style.css">
  
    
      <style>
        
      </style>
    
  

  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/>
  <meta name="groc-relative-root" content="../../../"/>
  <meta name="groc-document-path" content="../spec/shapes/polygon.coffee"/>
  
</head>
<body>
  <div id="file-area">
    <div id="meta">
      <code class="file-path">
      
        <a href="https://github.com/legomushroom/mojs.git/blob/master/../spec/shapes/polygon.coffee">../spec/shapes/polygon.coffee</a>
      
      </code>
    </div>
    <div id="document">
    
      <div class="segment">
      
      
        <div class="code"><div class="wrapper">Polygon  = mojs.Polygon
Bit     = mojs.Bit
ns      = <span class="hljs-string">'http://www.w3.org/2000/svg'</span>
svg     = <span class="hljs-built_in">document</span>.createElementNS?(ns, <span class="hljs-string">"svg"</span>)

describe <span class="hljs-string">'Polygon -&gt;'</span>, <span class="hljs-function">-&gt;</span>
  it <span class="hljs-string">'should extend Bit'</span>, <span class="hljs-function">-&gt;</span>
    polygon  = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg
    expect(polygon <span class="hljs-keyword">instanceof</span> Bit).toBe(<span class="hljs-literal">true</span>)

  it <span class="hljs-string">'should have points prop'</span>, <span class="hljs-function">-&gt;</span>
    tri = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg
    expect(tri.props.points).toBe <span class="hljs-number">3</span>
  it <span class="hljs-string">'should have recieve points prop'</span>, <span class="hljs-function">-&gt;</span>
    tri = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg, <span class="hljs-attribute">points</span>: <span class="hljs-number">8</span>
    expect(tri.props.points).toBe <span class="hljs-number">8</span>
  
  it <span class="hljs-string">'should call drawShape method'</span>, <span class="hljs-function">-&gt;</span>
    tri = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg, <span class="hljs-attribute">points</span>: <span class="hljs-number">8</span>
    spyOn tri, <span class="hljs-string">'drawShape'</span>
    tri.isDraw = <span class="hljs-literal">false</span>
    tri.draw()
    expect(tri.drawShape).toHaveBeenCalled()</div></div>
      
      </div>
    
      <div class="segment">
      
        <div class="comments ">
          <div class="wrapper"><p>it &#39;should call drawShape only once&#39;, -&gt;
  tri = new Polygon ctx: svg, points: 8
  spyOn tri, &#39;drawShape&#39;
  tri.draw()
  expect(tri.drawShape).not.toHaveBeenCalled()</p>
</div>
        </div>
      
      
        <div class="code"><div class="wrapper">  it <span class="hljs-string">'should calculate radialPoints'</span>, <span class="hljs-function">-&gt;</span>
    tri = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg
    expect(tri.radialPoints).toBeDefined()
    expect(tri.radialPoints.length).toBe tri.props.points
  it <span class="hljs-string">'should calculate radialPoints'</span>, <span class="hljs-function">-&gt;</span>
    tri = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg
    expect(tri.radialPoints).toBeDefined()
    expect(tri.radialPoints.length).toBe tri.props.points

  describe <span class="hljs-string">'draw -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should add properties to el'</span>, <span class="hljs-function">-&gt;</span>
      svg = <span class="hljs-built_in">document</span>.createElementNS?(ns, <span class="hljs-string">"svg"</span>)
      tri = <span class="hljs-keyword">new</span> Polygon
        <span class="hljs-attribute">ctx</span>:      svg
        <span class="hljs-attribute">radius</span>:   <span class="hljs-number">20</span>
      d   = tri.el.getAttribute(<span class="hljs-string">'d'</span>)
      d2  = <span class="hljs-string">'M0.0000,-20.0000 L17.3205,10.0000 L-17.3205,10.0000 z'</span>
      isD = d <span class="hljs-keyword">is</span> d2
      isIE9D = d <span class="hljs-keyword">is</span> <span class="hljs-string">'M 0 -20 L 17.3205 10 L -17.3205 10 Z'</span>
      expect(isD <span class="hljs-keyword">or</span> isIE9D).toBe <span class="hljs-literal">true</span>
    it <span class="hljs-string">'should work with radiusX and fallback to radius'</span>, <span class="hljs-function">-&gt;</span>
      svg = <span class="hljs-built_in">document</span>.createElementNS?(ns, <span class="hljs-string">"svg"</span>)
      tri = <span class="hljs-keyword">new</span> Polygon
        <span class="hljs-attribute">ctx</span>:      svg
        <span class="hljs-attribute">radius</span>:   <span class="hljs-number">20</span>
        <span class="hljs-attribute">radiusX</span>:  <span class="hljs-number">40</span>
      d   = tri.el.getAttribute(<span class="hljs-string">'d'</span>)
      d2  = <span class="hljs-string">'M0.0000,-20.0000 L34.6410,10.0000 L-34.6410,10.0000 z'</span>
      isD = d <span class="hljs-keyword">is</span> d2
      isIE9D = d <span class="hljs-keyword">is</span> <span class="hljs-string">'M 0 -20 L 34.641 10 L -34.641 10 Z'</span>
      expect(isD <span class="hljs-keyword">or</span> isIE9D).toBe <span class="hljs-literal">true</span>

    it <span class="hljs-string">'should work with radiusY and fallback to radius'</span>, <span class="hljs-function">-&gt;</span>
      svg = <span class="hljs-built_in">document</span>.createElementNS?(ns, <span class="hljs-string">"svg"</span>)
      tri = <span class="hljs-keyword">new</span> Polygon
        <span class="hljs-attribute">ctx</span>:      svg
        <span class="hljs-attribute">radius</span>:   <span class="hljs-number">20</span>
        <span class="hljs-attribute">radiusY</span>:  <span class="hljs-number">40</span>
      d   = tri.el.getAttribute(<span class="hljs-string">'d'</span>)
      d2  = <span class="hljs-string">'M0.0000,-40.0000 L17.3205,20.0000 L-17.3205,20.0000 z'</span>
      isD = d <span class="hljs-keyword">is</span> d2
      isIE9D = d <span class="hljs-keyword">is</span> <span class="hljs-string">'M 0 -40 L 17.3205 20 L -17.3205 20 Z'</span>
      expect(isD <span class="hljs-keyword">or</span> isIE9D).toBe <span class="hljs-literal">true</span>
    it <span class="hljs-string">'should call super method'</span>, <span class="hljs-function">-&gt;</span>
      svg     = <span class="hljs-built_in">document</span>.createElementNS?(ns, <span class="hljs-string">"svg"</span>)
      polygon  = <span class="hljs-keyword">new</span> Polygon <span class="hljs-attribute">ctx</span>: svg
      spyOn(Polygon.__super__, <span class="hljs-string">'draw'</span>)
      polygon.draw()
      expect(Polygon.__super__.draw).toHaveBeenCalled()

  describe <span class="hljs-string">'getLength method'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should calculate total length of the path'</span>, <span class="hljs-function">-&gt;</span>
      radius = <span class="hljs-number">100</span>
      bit = <span class="hljs-keyword">new</span> Polygon
        <span class="hljs-attribute">ctx</span>:    <span class="hljs-built_in">document</span>.createElementNS ns, <span class="hljs-string">'svg'</span>
        <span class="hljs-attribute">radius</span>: radius
      expect(bit.getLength().toFixed(<span class="hljs-number">1</span>)).toBe <span class="hljs-string">'519.6'</span>

    it <span class="hljs-string">'should calculate total length of the with different radiusX/Y'</span>, <span class="hljs-function">-&gt;</span>
      radiusX = <span class="hljs-number">100</span>
      radiusY = <span class="hljs-number">50</span>
      bit = <span class="hljs-keyword">new</span> Polygon
        <span class="hljs-attribute">ctx</span>:    <span class="hljs-built_in">document</span>.createElementNS ns, <span class="hljs-string">'svg'</span>
        <span class="hljs-attribute">radiusX</span>: radiusX
        <span class="hljs-attribute">radiusY</span>: radiusY
      expect(bit.getLength().toFixed(<span class="hljs-number">2</span>)).toBe <span class="hljs-string">'402.33'</span>






</div></div>
      
      </div>
    
    </div>
  </div>

  <script src="../../../toc.js"></script>
  <script src="../../../assets/libs.js"></script>
  <script src="../../../assets/behavior.js"></script>

  
    
      <script>
        
      </script>
    
  
</body>
</html>